<?php
	
	$accountCreditCardNoErrorMessage = '';
	$accountValidationError = new validation();
	if(isset($_POST['btnSavePayment']))
	{	
		
		$accountCreditCardNoErrorMessage = $accountValidationError->isEmpty(trim($_POST['creditcard_no']),'<label class="required">Enter a credit card number. </label>');

		if(!$accountCreditCardNoErrorMessage )
		{
			$accountCreditCardNoErrorMessage = $accountValidationError->isCreditCardNo(trim($_POST['creditcard_no']),'<label class="required">Must be a 16 digit number. </label>');
		}
	}
?>

<?php
	if(isset($_POST['btnSavePayment']))
	{	
		if($accountValidationError->status == 0)
		{
			try
			{
				if($currentUser->changeCreditCard($_POST['creditcard_no']))
				{
					$cartMessage = '<span class="success_msg_span">credit card no was saved successfully.</span>';
				}
				else
				{
					$cartMessage = '<span class="failed_msg_span">An error occured while saving your credit card number.</span>';
				}
			}
			catch(Exception $ex)
			{
				$cartMessage = '<span class="failed_msg_span">'.$ex->getMessage().'</span>';
			}
		}
	}
?>